﻿

namespace Deixei.WebApplication.Areas.Admin.Controllers
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Deixei.Domain;
    using Deixei.Web.Controllers;
    using Deixei.Infrastructure;
    using System.Reflection;
    using Deixei.Web.Attributes;
    
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;

    public class PortfolioController : DeixeiController
    {
        //
        // GET: /Admin/Portfolio/

        public ActionResult Index()
        {
            return View();
        }


        public ActionResult PortfolioIndexScript()
        {
            return View();
        }

        [AjaxRequest]
        public JsonResult GetNavigationAreasByPage(int ApplicationId, int index, int pageSize)
        {
            var data = this.ApplicationContext.ServiceLayerContext.NavigationService.GetNavigationAreas(ApplicationId).ToPagedList<NavigationArea>(index, pageSize);
            return Json(data, JsonRequestBehavior.AllowGet);
        }


        [HttpPost]
        [AjaxRequest]
        public JsonResult AddNavigationArea(NavigationArea obj)
        {
            CommonUtil.CheckForNull(obj, "AddNavigationArea obj");
            var data = this.ApplicationContext.ServiceLayerContext.NavigationService.AddNavigationArea(obj);
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        [AjaxRequest]
        public JsonResult EditNavigationArea(NavigationArea obj)
        {
            CommonUtil.CheckForNull(obj, "EditNavigationArea obj");
            var data = this.ApplicationContext.ServiceLayerContext.NavigationService.EditNavigationArea(obj);
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        [AjaxRequest]
        public JsonResult DeleteNavigationArea(int id)
        {
            CommonUtil.CheckForNull(id, "DeleteNavigationArea Id");
            if ( id > 0 ) {
                var data = this.ApplicationContext.ServiceLayerContext.NavigationService.DeleteNavigationArea(id);
                return Json(data, JsonRequestBehavior.AllowGet);
            }
            MessageResult r = new MessageResult() { Status = MessageStatus.Error, Message = "Navigation Area Id has to be greater than zero." };
            return Json(r, JsonRequestBehavior.AllowGet);
        }

        // WebAppPortfolio Ajax Requests Start
        // Get(), Add(WebAppPortfolio), Edit(WebAppPortfolio), Delete(Id)
        //[AjaxRequest]
        //public JsonResult GetWebAppPortfolio(int index, int pageSize)
        //{
        //    var data = this.ApplicationContext.ServiceLayerContext.NavigationService.GetWebAppPortfolio().ToPagedList<WebAppPortfolio>(index, pageSize);
        //    return Json(data, JsonRequestBehavior.AllowGet);
        //}
        [AjaxRequest]
        public JsonResult GetWebAppPortfolio()
        {
            var data = this.ApplicationContext.ServiceLayerContext.NavigationService.GetWebAppPortfolio().ToList();
            return Json(data, JsonRequestBehavior.AllowGet);
        }
        [HttpPost]
        [AjaxRequest]
        public JsonResult AddWebAppPortfolio(WebAppPortfolio obj)
        {
            CommonUtil.CheckForNull(obj, "AddWebAppPortfolio obj");
            var data = this.ApplicationContext.ServiceLayerContext.NavigationService.AddWebAppPortfolio(obj);
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        [AjaxRequest]
        public JsonResult EditWebAppPortfolio(WebAppPortfolio obj)
        {
            CommonUtil.CheckForNull(obj, "EditWebAppPortfolio obj");
            var data = this.ApplicationContext.ServiceLayerContext.NavigationService.EditWebAppPortfolio(obj);
            return Json(data, JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        [AjaxRequest]
        public JsonResult DeleteWebAppPortfolio(int id)
        {
            CommonUtil.CheckForNull(id, "DeleteWebAppPortfolio Id");
            if ( id > 0 )
            {
                var data = this.ApplicationContext.ServiceLayerContext.NavigationService.DeleteWebAppPortfolio(id);
                return Json(data, JsonRequestBehavior.AllowGet);
            }
            MessageResult r = new MessageResult() { Status = MessageStatus.Error, Message = "Web Application Portfolio Id has to be greater than zero." };
            return Json(r, JsonRequestBehavior.AllowGet);
        }

    }
}
